﻿<CodeSnippetTabbed DocLink="https://docs.devexpress.com/Blazor/DevExpress.Blazor.DxFormLayout#bind-to-data">
    <CodeSnippetTabPage Text="Razor">@(@"<DxFormLayout Data=""@editFormData""
              ItemUpdating=""@((pair) => OnItemUpdating(pair.Key, pair.Value))"">
    <DxFormLayoutItem Field=""@nameof(FormDataItem.Name)"" Caption=""Contact Name:"" ColSpanMd=""6"" />
    <DxFormLayoutItem Field=""@nameof(FormDataItem.BirthDate)"" Caption=""Birth Date:"" ColSpanMd=""6"" />
    <DxFormLayoutItem Field=""@nameof(FormDataItem.YearsWorked)"" Caption=""Years Worked:"" ColSpanMd=""6"" />
    <DxFormLayoutItem Field=""@nameof(FormDataItem.Position)"" Caption=""Position:"" ColSpanMd=""6"">
        <Template>
            <DxComboBox Data=""@(new List<string>() { ""Sales Representative"", ""Designer"" })""
                        Value=""@(((string)((ValueEditContext)context).Value))""
                        ValueChanged=""@(value => ((ValueEditContext)context).OnChanged(value))""></DxComboBox>
        </Template>
    </DxFormLayoutItem>
    <DxFormLayoutItem Field=""@nameof(FormDataItem.OnVacation)"" Caption=""On Vacation:"" ColSpanMd=""6"" />
</DxFormLayout>

@code {
    FormDataItem editFormData = new FormDataItem()
    {
        Name = ""Nancy Davolio"",
        BirthDate = DateTime.Now.AddYears(-30),
        YearsWorked = 3,
        Position = ""Sales Representative""
    };

    void OnItemUpdating(string fieldName, object newValue)
    {
        if (fieldName == nameof(FormDataItem.Name)) {
            editFormData.Name = newValue.ToString();
        } else if (fieldName == nameof(FormDataItem.BirthDate)) {
            editFormData.BirthDate = (DateTime)newValue;
        } else if (fieldName == nameof(FormDataItem.YearsWorked)) {
            editFormData.YearsWorked = (int)newValue;
        } else if (fieldName == nameof(FormDataItem.Position)) {
            editFormData.Position = newValue.ToString();
        } else if (fieldName == nameof(FormDataItem.OnVacation)) {
            editFormData.OnVacation = (bool)newValue;
        }
    }
}")</CodeSnippetTabPage>
</CodeSnippetTabbed>
